<?php
namespace App;

use Illuminate\Database\Eloquent\Model;

class Products extends Model
{
    protected $table = 'mall_products';

    public function types()
    {
        return $this->belongsToMany('App\productsType', 'mall_products_type_relate', 'products_id', 'products_type_id');
    }

    /**
     * 商品上下架
     * @return array
     */
    public static function getOnSaleList()
    {
        return [
            0 => '下架',
            1 => '上架'
        ];
    }


    /**
     * 取得商品状态
     * @param $on_sale
     * @return mixed|string
     */
    public static function getOnSale($on_sale)
    {
        return isset(self::getOnSaleList()[$on_sale]) ? self::getOnSaleList()[$on_sale] : '';
    }

    /**
     * 商品标签列表
     * @return array
     */
    public static function getTagList()
    {
        return [
            1 => '热门',
            2 => '最新'
        ];
    }

    /**
     * 取得标签
     * @param $tag
     * @return mixed|string
     */
    public static function getTag($tag)
    {
        return isset(self::getTagList()[$tag]) ? self::getTagList()[$tag] : '';
    }
}